package com.qifenqian.turbot.module.adapter.restaurant

import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseItemDraggableAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.qifenqian.turbot.R
import com.qifenqian.turbot.module.entity.response.restaurant.RestaurantPhotoEntity
import kotlinx.android.synthetic.main.item_restaurant_photo.view.*

/**
 * @author H
 * @createTime 2018/12/20 10:10
 * @description
 * @see
 * @since
 */
class PhotoAdapter(var list: MutableList<RestaurantPhotoEntity>?) : BaseItemDraggableAdapter<RestaurantPhotoEntity, BaseViewHolder>(R.layout.item_restaurant_photo, list) {

    override fun convert(helper: BaseViewHolder, item: RestaurantPhotoEntity) {
        val view = helper.itemView
        val options = RequestOptions().error(R.mipmap.ic_launcher)
        Glide.with(mContext).load(item.restaurantPhotoPath).apply(options).into(view.iv_item_restaurant_photo)
        view.btn_item_restaurant_photo_delete.setOnClickListener {
            if (onDeletePhotoListener != null) {
                onDeletePhotoListener!!.deletePhoto(helper.layoutPosition)
            }
        }
    }

    private var onDeletePhotoListener: OnDeletePhotoListener? = null

    fun setOnDeletePhotoListener(listener: OnDeletePhotoListener) {
        onDeletePhotoListener = listener
    }

    interface OnDeletePhotoListener {
        fun deletePhoto(position: Int)
    }
}
